Skip to content

Adding typehints and overloads for typing properties#125

Closed
julianstirling wants to merge 1 commit intomainfrom
typehint-property
Closed

Adding typehints and overloads for typing properties#125
julianstirling wants to merge 1 commit intomainfrom
typehint-property

Conversation

@julianstirling
Copy link
Copy Markdown
Contributor

@julianstirling julianstirling commented Jun 30, 2025

Making ThingProperty itself a generic type seems to work for getting mypy to type a property, as long as you use typing @overload decorators to tell it when it is returning the descriptor rather than the value:

image

If we go with this, we need to think about how we remove model so we are not double defining they type.

This needs work to get MyPy passing on LabThings itself. The implementation is based off this stack exchange thread.

I minimised the number of inputs needed to Generic. But also ruff got angry with "Descriptor" as the type hint. So I tried using TypeVar("Descriptor") but this upsets MyPy. Need to understand exactly what should be done.

@julianstirling
Copy link
Copy Markdown
Contributor Author

This was superseded by #127, so closing.

It is worth noting that #127 is now also closed as on review it was decided to give properties a larger underlying refactor to make their use more consistent and clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant